/*
* alipay jsapi
* @params ${callback} 回调执行函数
* */
export function alipayOnReady(callback) {
  if (window.AlipayJSBridge) callback && callback()
  else document.addEventListener('AlipayJSBridgeReady', callback, false)
}

/*
* 退出当前应用
* */
export function alipayExitApp() {
  alipayOnReady(() => {
    AlipayJSBridge.call('exitApp')
  })
}

/*
* 设置支付宝标题名称
* */
export function alipaySetTitle(name) {
  alipayOnReady(() => {
    AlipayJSBridge.call('setTitle', {title: name})
  })
}

/*
* 隐藏右上角按钮属性
* */
export function alipayHideOptionMenu() {
  alipayOnReady(() => {
    AlipayJSBridge.call('hideOptionMenu')
  })
}

/*
* 获取用户地址经纬度
* */
export function alipayGetLocation({cacheTimeout, requestType, timeout, bizType, cb}) {
  alipayOnReady(() => {
    AlipayJSBridge.call('getCurrentLocation', {
      cacheTimeout: cacheTimeout,
      requestType: requestType,
      timeout: timeout,
      bizType: bizType
    }, (result) => {
      cb(result)
    })
  })
}
